/* Registration phase - performed once for each component.
 * Container has to remember hash of component in order to avoid
 * registering it multiple times, although multiple registrations
 * should be safe. Well, safe-ish - new types will be registered,
 * which means that checking the type of an object against a known
 * registered type value is unreliable if multiple registrations
 * are allowed.
 */

static KewSelector sel_foo;
static KewCallShape shape_s_s;
static KewType mytype;

/* Note: it must be safe to call this function arbitrarily many
 * times, though it doesn't have to be efficient to do this. 
 * The VM will store the activation closure and reuse it whenever a component with the same
 * fingerprint is to be activated. */

KewActivationClosure kew_component_register()
{
    sel_foo = kew_selector_register("foo");
    shape_s_s = kew_call_shape_register(1, 0, 1, 0);
    mytype = kew_type_register(KEW_HERE);
    kew_method_register(mytype, sel_foo, shape_s_s, my_method);
    return kew_activation_closure_new(my_activation_function, NULL);
    /* this could return a list of required captured names, but what would the API in Kew then look like? */
}

static KewObject *my_activation_function(gpointer activation_function_data, KewSandboxObject *sandbox, GHashTable *initial_references)
{
    KewUserObject *new_object = kew_user_object_new(sandbox, mytype);
    new_object->captures[0] = g_hash_table_lookup(initial_references, "Baz"); /* FIXME: this yields unsafe behaviour if not found */
    return new_object;
}
